<template>
  <div class="kgapp_wrapper" id="kgapp">
    <iframe frameborder="0" :src="src" ref="iframe"></iframe>
  </div>
</template>

<script>
import nodeLegends from './model/nodeLegend'
export default {
  mixins:[nodeLegends],
  data() {
    let baseUrl = atlasUrl;
    return {
      urls: {
        baseUrl: baseUrl,
        fetchAltasUrl: baseUrl + "/weaponry/getNodes"
      },
      src: "./static/kgapp/index.html"
    };
  },
  mounted(){
    let _this = this
    const iframeRef = this.$refs.iframe
    this.getType()
    iframeRef.onload = function(){
      _this.iframeWin = iframeRef.contentWindow
      _this.getAltas()
    }
  },
  methods:{
    //  获取图谱的数据
    getAltas() {
      let _this = this;
      this.httpClient(this, {
        type: "get",
        url: this.urls.fetchAltasUrl,
        param: {},
        hideSuccessTip: true,
        ignoreEmptyData: true,
        fullSuccess: true,
        success: function(res) {
          let data = res.value;
          _this.iframeWin.postMessage({
            data:{
               nodes:data.nodes.map(item=>{
                 _this.getImage(item)
                 return {
                   ...item,
                   label:item.name,
                   properties:{
                     ...item
                   }
                 }
               }),
               links:data.links.map(item=>{
                 return {
                   ...item,
                   label:item.relation,
                   lineWidth:3
                 }
               })
            },
            baseUrl: _this.urls.baseUrl,
            // baseUrl:_this.atlasRemoteUrl,
            defaultUrl: _this.remoteUrl
           },"*")
        },
        error: function( err){
        }
      });
    },
  }
};
</script>

<style lang="scss" scoped>
.kgapp_wrapper {
  height: 100%;
  overflow: hidden;
  iframe {
    width: 100%;
    height: 100%;
  }
}
</style>
